/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：DialogScreen.java <br>
 * 创建时间：2013-7-26 上午10:23:58 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui.core;

import lostland.gmud.exv2.blgframework.CScreen;
import lostland.gmud.exv2.blgframework.IInput;
import lostland.gmud.exv2.blgframework.impl.SingleTouchHandler;

/**
 * 类名：DialogScreen <br>
 * 说明：有边框的screen，只在边框内生效喵！
 *
 * @author 12548
 */
public abstract class DialogScreen extends CScreen {

	protected GmudWindow __border;

	protected boolean td;

	protected boolean pretd;
	protected int downx, downy;


	protected abstract void onTouchDown(int tx, int ty);

	protected abstract void onTouchMove(int tx, int ty);

	protected abstract void onTouchUp(int tx, int ty);

	protected abstract void onClick(int tx, int ty);

	public abstract void onCancel();


	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.CScreen#update(float)
	 */
	@Override
	public void update(float deltaTime) {
		IInput i = getGame().getInput();
		int tx = SingleTouchHandler.touchX;
		int ty = SingleTouchHandler.touchY;
		pretd = td;
		getGame().getInput().getKeyEvents();
//		game.getInput().getTouchEvents();
		td = i.isTouchDown(0);
		if (td && !pretd) {
			downx = tx;
			downy = ty;
			onTouchDown(tx, ty);
		} else if (!td && pretd) {
			if (__border.inBound(tx, ty) && __border.inBound(downx, downy)) {
				onClick(tx, ty);
			} else if (!(__border.inBound(tx, ty) || __border.inBound(downx, downy))) {
				onCancel();
			} else {
				onTouchUp(tx, ty);
			}
		} else {
			onTouchMove(tx, ty);
		}
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.CScreen#isStable()
	 */
	@Override
	public boolean isStable() {
		return true;
	}


}
